package action;
/**
 * 根据图书编号查询图书数据并转发到详情页
 */

import dao.BookDao;
import dao.CollectDao;
import po.Book;
import po.User;
import vo.BookVo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/user/action/DetailServlet")
public class DetailServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Book book = new Book();
        book.setIsbn(req.getParameter("isbn"));
        BookDao bookDao = new BookDao();
        Book b = bookDao.selectByIsbn(book);
        User user = (User)req.getSession().getAttribute("user");
        String phone = user.getPhone();
        CollectDao collectDao = new CollectDao();
        Integer rid = collectDao.selectByProductAndUserId(book.getIsbn(),phone);
        BookVo bookVo = new BookVo();
        bookVo.setBook(b);
        bookVo.setRid(rid);
        req.setAttribute("bookVo",bookVo);
        req.getRequestDispatcher("../page/detail.jsp").forward(req,resp);
    }
}
